<?php

class BonusOption extends DataExtension implements PermissionProvider {
	private static $db = array(
		'NoUnilevelPayout' => 'Boolean',
		'NoPairingPayout' => 'Boolean',
		'NoMatchingPayout' => 'Boolean',
		'NoInvestPayout' => 'Boolean'
	);
	
	function updateFieldLabels(&$labels) {
        $labels['NoUnilevelPayout'] = _t('BonusOption.NO_UNILEVEL_PAYOUT', 'No unilevel payout');
		$labels['NoPairingPayout'] = _t('BonusOption.NO_PAIRING_PAYOUT', 'No pairing payout');
		$labels['NoMatchingPayout'] = _t('BonusOption.NO_MATCHING_PAYOUT', 'No matching payout');
		$labels['NoInvestPayout'] = _t('BonusOption.NO_INVEST_PAYOUT', 'No invest payout');
	}
	
	function updateCMSFields(FieldList $fields) {
		if(!Permission::check('ALLOW_BonusOption')){
			$fields->removeByName('NoUnilevelPayout');
        	$fields->removeByName('NoPairingPayout');
			$fields->removeByName('NoMatchingPayout');
			$fields->removeByName('NoInvestPayout');
		}
    }

	function updateFrontendFields(FieldList $fields) {
		$fields->removeByName('NoUnilevelPayout');
        $fields->removeByName('NoPairingPayout');
		$fields->removeByName('NoMatchingPayout');
		$fields->removeByName('NoInvestPayout');
    }

	function updateMemberFormFields(FieldList $fields) {
        $fields->removeByName('NoUnilevelPayout');
        $fields->removeByName('NoPairingPayout');
		$fields->removeByName('NoMatchingPayout');
		$fields->removeByName('NoInvestPayout');
    }

	public function providePermissions() {
        return array(
            'ALLOW_BonusOption' => array(
                'name' => _t('BonusOption.PERMISSION_ALLOW_BONUS_OPTION', 'Allow edit bonus option'),
                'category' => ''
            )
        );
    }
}
